/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.TestManage;

import GUI.MainFunction;
import connection.ManLabConnection;
import entities.TestDetail;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Admin
 */
public class DeleteTest {

    private TestDetail testDetail;
    private ArrayList<TestDetail> testDetails;
    private MainFunction parentFrame;
    private ManLabConnection cnn;
    private ArrayList<String> qry;

    public DeleteTest(ArrayList<TestDetail> testDetails, TestDetail testDetail, MainFunction parentFrame) {
        this.testDetail = testDetail;
        this.testDetails = testDetails;
        this.parentFrame = parentFrame;
        this.cnn = new ManLabConnection();
        this.qry = new ArrayList<String>();
    }
    
    

    public void deleteTest() {
        int tID = testDetail.getTest().getTestID();
boolean cn=        cnn.createConnection();
        String qry1 = "delete from ItemRequire where testID=" + tID + "";
        qry.add(qry1);
        String qry2 = "delete from BillDetail where testID=" + tID + "";
        qry.add(qry2);
        String qry3 = "delete from Report where testID=" + tID + "";
        qry.add(qry3);
        String qry4 = "delete from Test where testID=" + tID + "";
        qry.add(qry4);
        for (String s : qry) {
            cnn.executeQuery(s);
        }
        cnn.closeConnection();
        testDetails.remove(testDetail);
        JOptionPane.showMessageDialog(parentFrame, "Deleted successfully!!!");
        this.parentFrame.refreshReportTableView();
    }
}
